<template>
	<view class="mm">
		<view class="status_bar"></view>
		<view :class="'fui-toast ' + (FoxUIToast.show?'in':'out')">
			<view class="text">{{FoxUIToast.text}}</view>
		</view>
		<view class="fui-cell-group">
			<view class="fui-title">商品名称</view>
			<view class="fui-input"><textarea placeholder="请输入商品名称" id="title" auto-height v-model="title" /></view>
		</view>
		<view v-if="1==2" class="fui-cell-group">
			<view class="fui-title">副标题</view>
			<view class="fui-input"><input type="text" placeholder="请输入商品副标题" value="" id="subtitle" v-model="subtitle"></view>
		</view>
		<view class="fui-cell-group" v-if="1==2">
			<view class="fui-title">单位</view>
			<view class="fui-input"><input type="text" placeholder="请输入商品单位" value="" id="unit" v-model="unit"></view>
		</view>
		<view class="fui-cell-group">
			<view class="fui-title">主图<text @tap="sqm('首张图片为商品主图(拖拽可排序)')" class="icon pad icon-bangzhu1"></text></view>
			<shmily-drag-image cols=5 :list.sync="thumbs" ref="thumbs" ></shmily-drag-image>
		</view>
		<view id="thumbs3">
			<view class="fui-cell-group" data-action="type">
				<view class="fui-title">商品类型</view>
				<view class="fui-cell fui-choose">
					<view v-if="id==''" class="fui-cell-info" @tap="actionSheetTap('type')">{{type.name}}</view>
					<view v-else class="fui-cell-info" >{{type.name}}</view>
					<view v-if="id==''" class="fui-cell-remark"></view>
					<view v-else >不可修改</view>
				</view>
			</view>
			<view  class="fui-cell-group" data-action="cate">
				<view class="fui-title">商品分类</view>
				<view class="fui-choose">
					<view class="fui-cell-info"><!-- {{classText==''?'未分类':classText}} -->
						<picker @change="bindPickerChange" :value="cateindex" :range="cate">
							<view class="uni-input">{{cate[cateindex]||"未选择"}}</view>
						</picker>
					</view>
					<view class="fui-cell-remark"></view>
				</view>
			</view>
			<view v-if="1==2" class="fui-cell-group" data-action="prop">
				<view class="fui-title">商品属性</view>
				<view class="fui-cell fui-choose">
					<view class="fui-cell-info">{{more_items_str==''?'无':more_items_str}}</view>
					<view class="fui-cell-remark" @click="open(['more_items'])">选择</view>			
				</view>
			</view>
		</view>
		<view class="fui-cell-group">
			<view class="fui-title">规格选择</view>
			<view class="fui-cell fui-sku" >
				 <radio-group class="flex" @change="radioChange">
				<label class="uni-list-cell uni-list-cell-pd item" v-for="(item, i) in radioData" :key="item.value">
						<view>
							<radio style="transform:scale(0.7)" :value="i" :checked="item.check == hasoption?true:false" />{{item.name}}
						</view>
						
				</label>
				</radio-group>
			</view>
		</view>
		<block v-if="hasoption!='1'">
		<view class="fui-cell-group">
			<view class="fui-title">原价</view>
			<view class="fui-input"><input type="number" placeholder="请输入商品原价" value="0" id="productprice" v-model="productprice"></view>
		</view>	
		<view class="fui-cell-group">
			<view class="fui-title">现价</view>
			<view class="fui-input"><input type="number" placeholder="请输入现价" class="fui-input" value="0" id="marketprice" v-model="marketprice"></view>
		</view>	
		<view class="fui-cell-group">
			<view class="fui-title">成本价</view>
			<view class="fui-input"><input type="number" placeholder="请输入商品成本价" class="fui-input" value="0" id="costprice" v-model="costprice"></view>
		</view>	
		<view class="fui-cell-group">
			<view class="fui-title">库存</view>
			<view class="fui-input"><input type="number" placeholder="请输入商品库存" class="fui-input"  id="total" v-model="total"></view>
		</view>	
		</block>
		<view class="fui-cell-group"  @click="showSpec" v-if="hasoption=='1'">
			<view class="fui-title fui-cell">
				<view class="fui-cell-info">多规格</view>
				<view class="fui-cell-remark">添加</view>
			</view>
			<view class="fui-cell fui-choose">
				<view class="fui-cell-info"><!-- <text @click="specState=true">添加</text> -->{{specDataStr}}</view>
				<!-- <view class="fui-cell-remark">添加</view>	 -->		
			</view>
		</view>
		<view class="fui-cell-group" data-action="totalcnf">
			<view class="fui-title">库存设置</view>
			<view class="fui-cell fui-choose" @tap="actionSheetTap('totalcnf')">
				<view class="fui-cell-info" >{{totalcnf.name}}</view>				
				<view class="fui-cell-remark"></view>				
			</view>
		</view>
		<view class="fui-cell-group fui-cell-click">
				<view class="fui-title">显示库存</view>
				<view class="fui-input"><switch :color="color" style="transform:scale(0.7)"   data-id="showtotal" :checked="showtotal" @change="switchChange" /></view>
		</view>
		<view v-if="1==2" class="fui-cell-group">
			<view class="fui-title">商品重量</view>
			<view class="fui-input"><input type="text" placeholder="请输入商品重量" class="fui-input" value="" id="weight" v-model="weight"></view>
		</view>
		<view v-if="1==2" class="fui-cell-group">
			<view class="fui-title">商品编码</view>
			<view class="fui-input"><input type="number" placeholder="请输入商品编码" class="fui-input" value="" id="goodssn" v-model="goodssn"></view>
		</view>
		<view  v-if="1==2" class="fui-cell-group">
			<view class="fui-title">商品条码</view>
			<view class="fui-input"><input type="number" placeholder="请输入商品条码" class="fui-input" value="" id="productsn" v-model="productsn"></view>
		</view>		
		<uni-section v-if="1==2" title="浏览权限" type="line"></uni-section>
		<uni-list v-if="1==2">
			<view class="fui-cell-group" data-action="viewlevel">
				<view class="fui-title">会员等级</view>
				<view class="fui-cell fui-choose" @click="open(['user'])">
					<view class="fui-cell-info" >{{user_str==''?'不限制':user_str}}</view>				
					<view class="fui-cell-remark"></view>				
				</view>
			</view>
			<view class="fui-cell-group" data-action="viewgroup">
				<view class="fui-title">会员分组</view>
				<view class="fui-cell fui-choose" @click="open(['userGroup'])">
					<view class="fui-cell-info" >{{userGroup_str==''?'不限制':userGroup_str}}</view>				
					<view class="fui-cell-remark"></view>				
				</view>
			</view>
		</uni-list>		
		<uni-section v-if="1==2" title="购买权限" type="line"></uni-section>
		<uni-list v-if="1==2">
			<view class="fui-cell-group" data-action="buylevel">
				<view class="fui-title">会员等级</view>
				<view class="fui-cell fui-choose" @click="open(['userGrade'])">
					<view class="fui-cell-info" >{{userGrade_str==''?'不限制':userGrade_str}}</view>				
					<view class="fui-cell-remark"></view>				
				</view>
			</view>
			<view class="fui-cell-group" data-action="viewgroup">
				<view class="fui-title">会员分组</view>
				<view class="fui-cell fui-choose" @click="open(['buyGroup'])">
					<view class="fui-cell-info" >{{buyGroup_str==''?'不限制':buyGroup_str}}</view>				
					<view class="fui-cell-remark"></view>				
				</view>
			</view>
		</uni-list>			
		<uni-section v-if="1==2" title="商品限购(0为不限)" type="line"></uni-section>
		<uni-list v-if="1==2">
			<view class="fui-cell-group">
				<view class="fui-title">单次最多购</view>
				<view class="fui-cell fui-choose">
					<view class="fui-cell-info" ><input type="number" placeholder="单次最多购买数量" value="0" id="maxbuy" v-model="maxbuy"></view>				
					<view class="fui-cell-remark noremark">件</view>				
				</view>
			</view>
			<view class="fui-cell-group">
				<view class="fui-title">单次最低购</view>
				<view class="fui-cell fui-choose">
					<view class="fui-cell-info" ><input type="number" placeholder="单次最低购买数量" value="0" id="minbuy"  v-model="minbuy"></view>				
					<view class="fui-cell-remark noremark">件</view>				
				</view>
			</view>
			<view class="fui-cell-group">
				<view class="fui-title">会员总限购</view>
				<view class="fui-cell fui-choose">
					<view class="fui-cell-info" ><input type="number" placeholder="单次最低购买数量" value="0" id="minbuy"  v-model="minbuy"></view>				
					<view class="fui-cell-remark noremark">件</view>				
				</view>
			</view>
		</uni-list>	
		
		<block v-if="1==2">
		<view class="fui-cell-group">
			<view class="fui-cell noactive">
				<view class="fui-cell-label ">会员折扣</view>
				<view class="fui-cell-info sw"><switch  :color="color" style="transform:scale(0.7)" data-id="isnodiscount" :checked="isnodiscount" @change="switchChange" /></view>
			</view>	
			<view class="fui-cell noactive">
				<view class="fui-cell-label ">参与分销</view>
				<view class="fui-cell-info sw"><switch checked :color="color" style="transform:scale(0.7)" data-id="nocommission" :checked="nocommission" @change="switchChange"/></view>
			</view>
			<view class="fui-cell-group" data-action="diyform">
				<view class="fui-title">表单选择</view>
				<view class="fui-cell fui-choose" @tap="actionSheetTap('diyform')">
					<view class="fui-cell-info" >{{diyform.title}}</view>				
					<view class="fui-cell-remark"></view>				
				</view>
			</view>
			<view class="fui-cell-group" data-action="diypage">
				<view class="fui-title">模板选择</view>
				<view class="fui-cell fui-choose" @tap="actionSheetTap('diypage')">
					<view class="fui-cell-info" >{{diypage.name}}</view>				
					<view class="fui-cell-remark"></view>				
				</view>
			</view>
		</view>
		</block>	
		<view v-if="1==2" class="fui-cell-group">
			<view class="fui-cell noactive">
				<view class="fui-cell-label ">货到付款</view>
				<view class="fui-cell-info sw"><switch :color="color" style="transform:scale(0.7)" data-id="cash"  :checked="cash" @change="switchChange"/></view>
			</view>	
			<view class="fui-cell noactive">
				<view class="fui-cell-label ">发票</view>
				<view class="fui-cell-info sw"><switch :color="color" style="transform:scale(0.7)" data-id="invoice"  :checked="invoice" @change="switchChange"/></view>
			</view>
		</view>
		<!--
		<view class="fui-cell-group fui-cell-click" @click="open(['yf'])">
			<view class="fui-cell check-param" data-action="dispatch">
				<view class="fui-cell-label">运费设置</view>
				<view class="fui-cell-info">{{dispatstr==''?'模板: 默认模板':dispatstr}}</view>
				<view class="fui-cell-remark"></view>
			</view>
		</view>
		-->
		<view v-if="1==2" class="fui-cell-group fui-cell-click">
			<view class="fui-cell noactive">				
				<view class="fui-cell-label ">商品上架</view>
				<view class="fui-cell-info sw"><switch :color="color" style="transform:scale(0.7)" data-id="status" :checked="status" @change="switchChange"/></view>
			</view>
		</view>
		<view v-if="1==2" class="fui-cell-group">
			<view class="fui-title">商品排序</view>
			<view class="fui-input"><input type="number" placeholder="数字越大，排名越靠前" class="fui-input" value="" id="displayorder" v-model="displayorder"></view>
		</view>	
		
		<!-- 插入详情图-->
		<view class="fui-cell-group">
			<view class="fui-title">详情图</view>
			<view class="fui-input">
				<textarea placeholder="请输入商品介绍" id="desc" auto-height v-model="desc" />
			</view>
			
			<shmily-drag-image cols=5 :list.sync="detailsThumbs" ref="detailsThumbs" ></shmily-drag-image>
			<view class="fui-title">商品详情图(拖拽可排序)</view>
		</view>
		
		<view class="fui-title center">更多设置请至PC端后台</view>
		<view class="status_bar"></view>
		<view class="fui-navbar">
			<view v-if="saveState" class="nav-item btn btn-submit" @click="save">保存</view>
			<view v-else class="nav-item btn btn-submit" @click="gdSave">保存</view>
		</view>
		<uni-transition :duration="500" :mode-class="modeClass" :styles="transfromClass" :show="transShow"  @change="change">
			<view class="status_bar"></view>
			<!-- 商品属性 -->
			 <checkbox-group v-if="modeClass[0]!='user'&&modeClass[0]!='userGrade'&&modeClass[0]!='class'&&modeClass[0]!='yf' && modeClass[0]!='userGroup'&& modeClass[0]!='buyGroup'" :data-type="modeClass[0]" @change="checkbox">
				<view class="fui-title">商品属性 </view> 
				<view class="fui-list-group">
				<label class="fui-list bindclick" v-for="item in select" :key="item.value">
					<view class="fui-list-media">
						<checkbox :value="item.value" :checked="item.checked" :color="color" style="transform:scale(0.8)" />
					</view>
					<view class="fui-list-inner">{{item.name}}</view>
				</label>
				</view>
			</checkbox-group> 
			<!-- 浏览权限 会员等级  购买权限 会员等级-->
			<checkbox-group v-if="modeClass[0]=='user'|| modeClass[0]=='userGrade'" :data-type="modeClass[0]" @change="checkbox">
				<view class="fui-title">商品属性 </view> 
				<view class="fui-list-group">
				<label class="fui-list bindclick" v-for="item in select" :key="item.value">
					<view class="fui-list-media">
						<checkbox :value="item.id+''" :checked="item.checked" :color="color" style="transform:scale(0.8)" />
					</view>
					<view class="fui-list-inner">{{item.levelname}}</view>
				</label>
				</view>
			</checkbox-group> 
			
			<!-- 会员等级、会员分组 -->
			 <checkbox-group v-if="modeClass[0]=='userGroup' || modeClass[0]=='buyGroup'" :data-type="modeClass[0]" @change="checkbox">
				<view class="fui-title">商品属性</view>
				<view class="fui-list-group">
				<label class="fui-list bindclick" v-for="item in select" :key="item.value">
					<view class="fui-list-media">
						<checkbox :value="item.id+''" :checked="item.checked" :color="color" style="transform:scale(0.8)" />
					</view>
					<view class="fui-list-inner">{{item.groupname}}</view>
				</label>
				</view>
			</checkbox-group> 
			
			<!-- 运费设置 -->
			<view v-if="modeClass[0]=='yf' ">
				<radio-group @change="yfRadio" >
					<view class="fui-title">运费设置</view>
					<view class="fui-list-group">
						<label class="fui-list bindclick" @click="ftemo" v-for="item in yfsutp" :key="item.value" >
							<view class="fui-list-media">
								<radio :value="item.value" :checked="item.checked" :color="color" style="transform:scale(0.8)"/>
							</view>
							<view class="fui-list-inner">{{item.name}}</view>
						</label>					
						
					</view>
				</radio-group>
				<radio-group  v-if="radioStup==0" @change="radioStupClick">
					<view class="fui-title">运费模板</view>
					<view class="fui-list-group">
						<label class="fui-list bindclick" v-for="(item,index) in dispatchid" :key="item.value">
							<view class="fui-list-media">
								<radio :value="index+''" :checked="item.checked" :color="color" style="transform:scale(0.8)"/>
							</view>
							<view class="fui-list-inner">{{item.name}}</view>
						</label>										
					</view>
				</radio-group>
				<view v-if="radioStup==1" >
					<view class="fui-title">统一运费</view>
					<view class="fui-cell-group">
						<view class="fui-cell fui-choose">
							<view class="fui-cell-label">邮费价格</view>
							<view class="fui-cell-info">
								<input type="number" placeholder="请输入统一运费" class="fui-input" value="" id="dispatchprice" v-model="dispatchprice">
							</view>
							<view class="fui-cell-remark noremark">元</view>
						</view>
					</view>
				</view>
			</view> 
			<!-- 商品分类 -->
			<!-- 商品分类 -->
			<view class="param-item param-cate" v-if="modeClass[0]=='class' ">

					
				<!-- <view class="fui-title">商品分类(多选)</view>
				<view class="cate-list" data-catlevel="3">
					<view class="item" data-level="1">
						<view  :class="{active:index==active0}" v-for="(item,index) in data.allcategory.parent" :key="index" @click="nactive(index)" data-id="3211">{{item.name}}</view>
						
					</view>
					<view class="item" data-level="2">
						<text v-if="navchind.length<1" class="empty">无子分类</text>
						<view v-else  :class="{active:index==active1}" v-for="(item,index) in navchind" :key="index" @click="nactive(index,1,item.id)" data-id="3211">{{item.name}}</view>
					</view>
					<view class="item" data-level="3">
						<text v-if="grandchildren.length<1" class="empty">无子分类</text>
						<view v-else :class="{active:index==active2}" v-for="(item,index) in grandchildren" :key="index" @click="nactive(index,2)" data-id="3211">{{item.name}}</view>
					</view>
				</view>
				<view class="btn btn-success btn-sm block btn-choose-cate" @click="selectClass">选择此分类</view>
				<view class="fui-title">已选择分类</view>
				<view class="small-block">
					<text class="item" v-for="(item,index) in classData" :key="index">{{classData[index].name}} <i class="icon icon-close" @click="del(index)" ></i></text>
				</view> -->
			</view>			
			
			<view class="fui-navbar">
				<view class="nav-item btn btn-success submit-params" style="display: table-cell;" @click="onTap">确定</view>
			</view>
		</uni-transition>
		<addspec  ref="addspec" @spec="spec"  ></addspec>
	</view>
</template>

<script>
	//import  addspec from "../../components/addspec/addspec.vue";
	import  addspec from "./components/addspec/addspec.vue";
	var t = getApp().globalData,
		e = t.requirejs('core'),
		i = t.requirejs('foxui'),
		a = t.requirejs('jquery');
	export default {
		components:{addspec},
		data() {
			return {
				FoxUIToast:{},
				desc:'',
				//是否启动多规格
				hasoption:'0',
				allspecs:[],
				options:[],
				specData:[],
				//规格拼装字符串
				specDataStr:'',
				//是否显示返回按钮
				back:true,
				//库存	
				total:'',
				//商品类型
				type:'',
				typeList:[
					{
						value: '1',
						name: '实体商品'
					},
					{
						value: '2',
						name: '虚拟商品'
					},
					{
						value: '3',
						name: '虚拟商品（卡密）'
					},
					
				],
				//库存设置
				totalcnf:'',
				totalcnfList:[
					{
						value: '0',
						name: '拍下减库存'
					},
					{
						value: '1',
						name: '付款减库存'
					},
					{
						value: '2',
						name: '永不减库存'
					},
		
					
				],
				//表单
				diyform:{
					'title':''
				},
				diyformList:[
				

				],
				//模板
				diypage:'',
				diypageList:[],
				//switch 颜色
				color:'#000',
				//显示 商品属性、会员等级、会员分组 
				transShow: false,
				//一级分类
				active0:'-1',
				//二级分类
				active1:'-1',
				//三级分类
				active2:'-1',
				//打开复选类型的窗口
				modeClass: ['fade'],
				//窗口样式
				maskClass: {
					'position': 'fixed',
					'bottom': 0,
					'top': 0,
					'left': 0,
					'right': 0,
					'background-color': 'rgba(0, 0, 0, 0.4)'
				},
				transfromClass: {
					'position': 'fixed',
					'bottom': 0,
					'top': 0,
					'left': 0,
					'right': 0,
					/* #ifndef APP-NVUE */
					// 'display': 'flex',
					/* #endif */
					'justify-content': 'center',
					'align-items': 'center',
					'background':'#f3f3f3',
					'z-index':'99'
				},
				//商品属性
				more_items_val:[],
				more_items_str:'',
				more_items: [{
						value: 'isrecommand',
						name: '推荐商品'
					},
					{
						value: 'isnew',
						name: '新品上市',
					},
					{
						value: 'ishot',
						name: '热卖商品'
					},
					{
						value: 'issendfree',
						name: '包邮商品'
					}
				],
				//浏览权限 会员等级
				user_val:[],
				user_str:'',
				user: [
					
				],
				//浏览权限 会员分组
				userGroup_val:[],
				userGroup_str:'',
				userGroup: [],
				//购买权限 会员等级
				userGrade_str:'',
				userGrade_val:[],
				userGrade: [
				],
				//购买权限 会员分组
				buyGroup_val:[],
				buyGroup_str:'',
				buyGroup: [],
				//open 打开窗口后显示复选的数组数据
				select:[],
				//子分类
				navchind:[],
				//孙分类
				grandchildren:[],
				//商品标题
				title:'',
				//副标题
				subtitle:'',
				//单位
				unit:'',
				//原价
				productprice:'',
				//现价
				marketprice:'',
				//成本价
				costprice:'',
				//商品重量
				weight:'',
				//商品编码
				goodssn:'',
				//商品条码
				productsn:'',
				//商品图片
				thumbs:[],
				//详情图片
				detailsThumbs:[],
				//会员折扣
				isnodiscount:true,
				//参与分销
				nocommission:true,
				//货到付款
				cash:false,
				//发票
				invoice:false,
				//是否上架
				status:false,
				//商品排序
				displayorder:'',
				//单次最多购
				maxbuy:'',
				//会员总限购
				usermaxbuy:'',
				//单次最低购
				minbuy:'',
				//存储分类id
				class_id:[],
				//存储分类名
				className:[],
				//分类id 和对应的分类名 存数组
				classData:[],
				//拼装各个分类名
				classText:'',
				//运费设置
				radioStup:0,
				//运费设置
				yfsutp:[
					{
						'name':'运费模板',
						'value':'0',
						'checked':true
					},
					{
						'name':'统一邮费',
						'value':'1',
						'checked':false
					}
				],
				//运费模板
				dispatchid:[
					{
						'name':'默认模板',
						'value':'0',
						'checked':true
					},
					{
						'name':'按件计费',
						'value':'23',
						'checked':false
					},
					{
						'name':'包邮',
						'value':'32',
						'checked':false
					},
					{
						'name':'消毒湿巾',
						'value':'45',
						'checked':false
					},
					{
						'name':'湿巾2',
						'value':'46',
						'checked':false
					},
					{
						'name':'喷雾',
						'value':'47',
						'checked':false
					},
					{
						'name':'酱油',
						'value':'48',
						'checked':false
					},
					{
						'name':'牛奶',
						'value':'49',
						'checked':false
					},
					{
						'name':'保安鸭爪',
						'value':'89',
						'checked':false
					},
				],
				//邮费价格
				dispatchprice:'',
				//显示运费字符串拼装
				dispatstr:'',
				//保存
				saveState:false,
				//显示库存
				showtotal:false,
				//id 不为空则是编辑 ,为空则为添加
				id:'',
				//分类数据
				data:{},
				cate:[],
				cateindex:0,
				radioData:[
					
					{
						'name':'单规格',
						'check':0
					},
					{
						'name':'多规格',
						'check':1
					}
				],
				//分类
				allcategory:[]
				
			}
			
		},
		onShow(){
			if(this.id==''){
				this.type=this.typeList[0]
				this.totalcnf=this.totalcnfList[0]

			}
		},
		onLoad(e){
			if('id' in e){
				this.id=e.id
				
			}
			this.dataUrl()
		},
		methods: {
			// 启用多规格复选事件
			checkboxChange(e) {
				this.hasoption=this.hasoption=="0"?"1":"0"
			},
			//单选
			radioChange(e){
		
				this.hasoption=e.target.value
			},
			
			showSpec(){
				 this.$refs.addspec.specState=true
			},
			dataUrl(){
				let s=this
				e.post('merchmanage.goods.init', {}, function(t) {
					s.data=t.result
					s.diyformList=s.data.diyform
					
					//表单数据
					let add={'id':0,'title':'不设置'}
					s.diyformList.unshift(add)
					add={id: '0',name: '默认模板'}
					//模板数据
					s.diypageList=s.data.diypage
					s.diypageList.unshift(add)
					//s.data.allcategory
					s.allcategory=s.data.allcategory
					//分类	
					Object.keys(s.data.allcategory).map((item)=>{
						s.cate.push(s.data.allcategory[item].name)
		
					})
					
					if(s.id==''){
						e.get('merchmanage.goods.edit', {}, function(t) {
							s.userGroup=t.result.group_list
							s.buyGroup=t.result.group_list
							s.userGrade=t.result.level_list
							s.user=t.result.level_list
							
							console.log(t.result.allspecs,s.allspecs);
						})
						s.default()
					}else{
						s.init(s.id)
					}
					
				})
				
			},
			//添加 默认显示第一个 表单 ,模板
			default(){
				this.diyform=this.diyformList[0]
				this.diypage=this.diypageList[0]
				
			},
			spec(data){
				this.allspecs=data.allspecs
				this.options=data.options
				this.optionsStr(this.options)
			},
			init(id){
				let s=this
				e.get('merchmanage.goods.edit', {id}, function(t) {
					s.userGroup=t.result.group_list
					s.buyGroup=t.result.group_list
					s.userGrade=t.result.level_list
					s.user=t.result.level_list
					s.allspecs=t.result.allspecs
					s.options=t.result.options
					s.cateindex=s.allcategory.findIndex(v => v.id === t.result.goods.cates)
					s.optionsStr(s.options)
					s.$nextTick(()=>{
							s.$refs.addspec.show({allspecs:s.allspecs,'options':s.options})
					})
					s.output(t.result.goods)
				})
				
			},
			//规格数据拼装
			optionsStr(data){
				let str=''
				Object.keys(data).map((item)=>{
					str+=data[item].title+','
				})
				str = str.substr(0,str.length-1);
				this.specDataStr=str	
				
			},
			output(data){
				// 是否启用规格
				this.hasoption=data.hasoption.toString()
				//商品图片
				if(data.thumbs.length==0)
					this.thumbs=[data.thumb]
				else
					this.thumbs=data.thumbs
				//详情图片 jack
				if(data.detailsThumbs){
					if(data.detailsThumbs.length==0)
						this.detailsThumbs=[data.detailsThumbs]
					else
						this.detailsThumbs=data.detailsThumbs
				}
						
				this.$nextTick(()=>{	
					this.$refs.thumbs.init(this.thumbs)
					if(data.detailsThumbs)
						this.$refs.detailsThumbs.init(this.detailsThumbs)
				})
				//商品名称
				this.title=data.title
				//副标题
				this.subtitle=data.subtitle
				//单位
				this.unit=data.unit
				//商品类型
				Object.keys(this.typeList).map((item)=>{
					if(this.typeList[item].value==data.type){
						this.type=this.typeList[item]
					}
				})
		
				//推荐商品
				if(data.isrecommand==1){
					this.more_items_val.push('isrecommand')
				}
				//新品上市
				if(data.isnew==1){
					this.more_items_val.push('isnew')
				}
				//热卖商品
				if(data.ishot==1){
					this.more_items_val.push('ishot')
				}
				//包邮商品
				if(data.issendfree==1){
					this.more_items_val.push('issendfree')
				}
				
				Object.keys(this.more_items).map((item)=>{
					if(this.more_items_val.includes(this.more_items[item].value)){
						this.more_items_str+=this.more_items[item].name+','
					}
				})
				//字符串拼装生成商品属性
				this.more_items_str=this.more_items_str.substring(0, this.more_items_str.length - 1)
				//库存设置
				Object.keys(this.totalcnfList).map((item)=>{
					if(this.totalcnfList[item].value==data.totalcnf)
						this.totalcnf=this.totalcnfList[item]
				})
				//显示库存
				if(data.showtotal==0)
					this.showtotal=false
				else
					this.showtotal=true
				
				// 浏览权限 会员等级 	
				this.user_val=data.showlevels.split(',')
				let user_dat=this.user_val;
	
				Object.keys(this.user).map((item)=>{
					this.user[item].id+=''
					if(user_dat.includes(this.user[item].id)){
						this.user_str+=this.user[item].levelname+','
					}
				})
				//字符串拼装生成商品属性
				this.user_str=this.user_str.substring(0, this.user_str.length - 1)
				// 浏览权限 会员分组
				this.userGroup_val=data.showgroups.split(',')
				user_dat=this.userGroup_val;
				Object.keys(this.userGroup).map((item)=>{
					this.userGroup[item].id+=''
					if(user_dat.includes(this.userGroup[item].id)){
						this.userGroup_str+=this.userGroup[item].groupname+','
					}
				})
				
		
				//字符串拼装生成商品属性
				this.userGroup_str=this.userGroup_str.substring(0, this.userGroup_str.length - 1)
				
				
				// 购买权限 会员等级
				this.userGrade_val=data.buylevels.split(',')
				user_dat=this.userGrade_val;
	
				Object.keys(this.userGrade).map((item)=>{
					this.userGrade[item].id+=''
					if(user_dat.includes(this.userGrade[item].id)){
						this.userGrade_str+=this.userGrade[item].levelname+','
					}
				})
				//字符串拼装生成商品属性
				this.userGrade_str=this.userGrade_str.substring(0, this.userGrade_str.length - 1)
				
				
				// 购买权限 会员分组
				this.buyGroup_val=data.buygroups.split(',')
				user_dat=this.buyGroup_val;
					
				Object.keys(this.buyGroup).map((item)=>{
					this.buyGroup[item].id+=''
					if(user_dat.includes(this.buyGroup[item].id)){
						this.buyGroup_str+=this.buyGroup[item].groupname+','
					}
				})
				//字符串拼装生成商品属性
				this.buyGroup_str=this.buyGroup_str.substring(0, this.buyGroup_str.length - 1)
				//会员折扣
				if(data.isnodiscount==1)
				{
					this.isnodiscount=false
				}else{
					this.isnodiscount=true
				}
			
				//参与分销
				if(data.nocommission==1)
				{
					this.nocommission=false
				}else{
					this.nocommission=true
				}
				//表单选择
				Object.keys(this.diyformList).map((item)=>{
					if(this.diyformList[item].id==data.diyformid)
						this.diyform=this.diyformList[item]
						
				})
				
				//模板选择
				Object.keys(this.diypageList).map((item)=>{
					if(this.diypageList[item].id==data.diypage)
						this.diypage=this.diypageList[item]
						
				})
				//货到付款
				if(data.cash==0)
				{
					this.cash=false
				}else{
					this.cash=true
				}
				//发票
				if(data.invoice==0)
				{
					this.invoice=false
				}else{
					this.invoice=true
				}
				//商品上架
				if(data.status==0)
				{
					this.status=false
				}else{
					this.status=true
				}
				//运费设置
				Object.keys(this.yfsutp).map((item)=>{
					if(this.yfsutp[item].value==data.dispatchtype){
						this.yfsutp[item].checked=true
						this.dispatstr=this.yfsutp[item].name
					}else{
						this.yfsutp[item].checked=false
					}
				})
				Object.keys(this.dispatchid).map((item)=>{
					if(this.dispatchid[item].value==data.dispatchid){
						this.dispatchid[item].checked=true
						this.dispatstr+=':'+this.dispatchid[item].name
					}else{
						this.dispatchid[item].checked=false
					}
				})
			
				//商品分类
				//this.cate=data.cates
				//原价
				this.productprice=data.productprice
				//请输入现价
				this.marketprice=data.marketprice
				//请输入商品成本价
				this.costprice=data.costprice
				//请输入商品呢库存
				this.total=data.total
				//请输入商品重量
				this.weight=data.weight
				//商品编码
				this.goodssn=data.goodssn
				//商品条码
				this.productsn=data.productsn
				//单次最多购买数量
				this.maxbuy=data.maxbuy
				//单次最低购买数量
				this.minbuy=data.minbuy
				//会员总限购买数量
				this.usermaxbuy=data.usermaxbuy
				//商品排序
				this.displayorder=data.displayorder
				//邮费价格
				this.dispatchprice=data.dispatchprice
				this.desc=data.desc
				this.detailsThumbs=data.detailsThumbs
			},
			
			gdSave(){
				let str=''
				if(this.thumbs.length<1){
					return uni.showToast({
					    title: '请选择图片',
						icon:"none",
					    duration: 2000
					});
				}
				if(this.title==''){
					return uni.showToast({
					    title: '请选择商品名称',
						icon:"none",
					    duration: 2000
					});
				}
				
				if(this.id==''){
					str='确定添加吗？'
				}else{
					str='确定保存编辑吗？'
				}
				uni.showModal({
				    title: '提示',
				    content: str,
				    success:  (res)=> {
				        if (res.confirm) {
				            this.sub()
				        } 
				    }
				});

			},
			sub(){
				let data={}
				//是否启用多规格
				data.hasoption=this.hasoption
				//商品标题
				data.title=this.title
				//标题
				data.subtitle=this.subtitle
				//单位
				data.unit=this.unit
				//商品图片
				data.thumbs=this.thumbs
				//商品详情图片
				data.detailsThumbs=this.detailsThumbs
				//商品分类
				data.cates=''
				Object.keys(this.classData).map((item)=>{
					data.cates+=this.classData[item].id+','
				})
				data.cates = data.cates.substring(0, data.cates.length - 1); 
				 //商品属性
				data.type=this.type.value
				Object.keys(this.more_items_val).map((item)=>{
					data[this.more_items_val[item]]=1
				})
				//原价
				data.productprice=this.productprice
				//现价
				data.marketprice=this.marketprice
				//成本价
				data.costprice=this.costprice
				//库存
				data.total=this.total
				//库存设置
				data.totalcnf=this.totalcnf.value
				//保存多规格
				data.allspecs=this.allspecs
				data.options=this.options
				//显示库存
				if(this.showtotal){
					data.showtotal=1
				}else{
					data.showtotal=0
				}
				//商品重量
				data.weight=this.weight
				//商品编码
				data.goodssn=this.goodssn
				//商品条码
				data.productsn=this.productsn
				//浏览权限 会员等级
				data.showlevels=this.user_val.join(",");
				//浏览权限 会员分组
				data.showgroups=this.userGroup_val.join(",");
				//购买权限 会员等级
				data.buylevels=this.userGrade_val.join(",");
				//购买权限 会员分组
				data.buygroups=this.buyGroup_val.join(",");
				//单次最多购
				data.maxbuy=this.maxbuy
				//单次最低购
				data.minbuy=this.minbuy
				//会员总限购
				data.usermaxbuy=this.usermaxbuy
				//会员折扣
				data.isnodiscount=this.isnodiscount?0:1
				//参与分销
				data.nocommission=this.nocommission
				//表单选择
				data.diyformid=this.diyform.id
				//模板选择
				data.diypage=this.diypage.value
				//货到付款
				data.cash=this.cash
				//发票
				data.invoice=this.invoice
				//商品上架
				data.status=this.status
				//商品排序
				data.displayorder=this.displayorder
				//运费设置
				Object.keys(this.yfsutp).map((item)=>{
					if(this.yfsutp[item].checked){
						data.dispatchtype=this.yfsutp[item].value
					}
				})
				//运费模板				
				Object.keys(this.dispatchid).map((item)=>{
					if(this.dispatchid[item].checked){
						data.dispatchid=this.dispatchid[item].value
					
					}
				})
				//统一运费
				data.dispatchprice=this.dispatchprice
				//分类数据

				data.cates=this.cateindex>-1?this.allcategory[this.cateindex].id:''
				data.desc=this.desc
				// jack 
				data.status=data.status==true?1:0	
				if(this.id==''){
					e.post('merchmanage.goods.add', data, function(t) {
						if(t.status==1){
							uni.showToast({
							    title: '添加成功',
								icon:"none",
							    duration: 2000
							});
							
						}else{
							uni.showToast({
							    title: '添加失败',
								icon:"none",
							    duration: 2000
							});
						}
						
					})
				}else{
					data.id=this.id
					e.post('merchmanage.goods.edit', data, function(t) {
						if(t.status==1){
							uni.showToast({
							    title: '修改成功',
								icon:"none",
							    duration: 2000
							});
							
						}else{
							uni.showToast({
							    title: '修改失败',
								icon:"none",
							    duration: 2000
							});
						}
						
					})
					
				}
			},
			//商品分类
			bindPickerChange(data){
				this.cateindex=data.detail.value
			},
			//运费模板
			radioStupClick(e){
				Object.keys(this.dispatchid).map((item)=>{
					this.dispatchid[item].checked=false
				})
				this.dispatchid[e.target.value].checked=true
			},
			sqm(r) {
				console.log(r);
				typeof(r) == 'string' ? i.toast(this, r): ''
			},
			//添加分类
			selectClass(){
				let name=this.className.join("-")
				let id=this.class_id[this.class_id.length-1]
				let select=false
				Object.keys(this.classData).map((item)=>{
					if(this.classData[item].id==id){
						select=true
						return 
					}
				})
				if(select){
					return uni.showToast({
						    title: '该分类已经选择',
							icon:"none",
						    duration: 2000
						});
				}
				
				this.classData.push({
					'name':name,
					'id':id
				})
				
			},
			//商品属性
			checkbox(e){
				let type=e.target.dataset.type
				this[type+'_val']=e.target.value
				
			},
			//显示库存
			switchChange(e){
				let key=e.target.dataset.id
				this[key]=e.target.value
			},
			
			//商品类型
			actionSheetTap(t) {
				let title='',itemList=[]
				let add=[]
				itemList=this[t+'List']
				if(t=='diyform'){
					Object.keys(itemList).map((item)=>{
						add.push(itemList[item].title)
					})
				}else{
					Object.keys(itemList).map((item)=>{
						add.push(itemList[item].name)
					})
				}
				
			
				uni.showActionSheet({
					itemList:add,
					success: (e) => {
						this[t]=itemList[e.tapIndex]
					}
				})
			},
			mask() {
				this.show = true
			},
			//打开复选按钮
			open(mode) {
				this.modeClass = mode
				this.saveState=true
				this.select=this[mode[0]]
				if(this.modeClass=='userGroup' ||this.modeClass=='buyGroup' || this.modeClass=='user' ||this.modeClass=='userGrade' ){
					Object.keys(this.select).map((item)=>{
						this.select[item].id+=''
						if(this[mode[0]+'_val'].indexOf(this.select[item].id)!=-1){
							this.select[item].checked=true
						}else{
							this.select[item].checked=false
						}
					
					})
					
				}
				else if(this.modeClass!='class'&&this.modeClass!='yf'){
					//this.more_items=mode[0]
					//console.log(this[mode[0]+'_val'])
					Object.keys(this.select).map((item)=>{
						if(this[mode[0]+'_val'].indexOf(this.select[item].value)!=-1){
							this.select[item].checked=true
						}else{
							this.select[item].checked=false
						}

					})
				}	
				this.transShow = !this.transShow
				this.back = false
			},
			save(){
				let sum=''
				this.transShow=false
				if(this.modeClass!='class'&&this.modeClass!='yf'){
				
					if(this.modeClass=='user' || this.modeClass=='userGrade'){
						Object.keys(this[this.modeClass+'_val']).map((item)=>{
							const index = this[this.modeClass].findIndex(v => v.id == this[this.modeClass+'_val'][item])
							sum+=this[this.modeClass][index].levelname+','
							
						})
					}
					else if(this.modeClass=='userGroup' || this.modeClass=='buyGroup'){
						Object.keys(this[this.modeClass+'_val']).map((item)=>{
							const index = this[this.modeClass].findIndex(v => v.id == this[this.modeClass+'_val'][item])
							sum+=this[this.modeClass][index].groupname+','
							
						})
					}else{
						Object.keys(this[this.modeClass+'_val']).map((item)=>{
							const index = this[this.modeClass].findIndex(v => v.value === this[this.modeClass+'_val'][item])
							sum+=this[this.modeClass][index].name+','
							
						})
					}

					sum = sum.substring(0, sum.length - 1);  
					this[this.modeClass+'_str']=sum
				}else if(this.modeClass=='class'){
					this.classText=''
					Object.keys(this.classData).map((item)=>{
						this.classText+=this.classData[item].name+','
					})
					this.classText = this.classText.substring(0, this.classText.length - 1);  
				}else if(this.modeClass=='yf'){
					let name='',val=''
					Object.keys(this.yfsutp).map((item)=>{
						if(this.yfsutp[item].checked){
							name+=this.yfsutp[item].name
							val=this.yfsutp[item].value
						}
					})
				
					Object.keys(this.dispatchid).map((item)=>{
						if(this.dispatchid[item].checked){
							if(val==1){
								name+=':'+this.dispatchprice
							}else{
								name+=':'+this.dispatchid[item].name
							}
							
						
						}
					})
					
					this.dispatstr=name
				}
				this.saveState=false
				this.back=true
			},
			onTap() {
				this.transShow = this.show = false
				this.back = true
			},
			change(e) {

			},
			//运费设置 是否显示统一邮费
			ftemo(){
				this.ftem1=true
				this.ftem2=false
			},
			//运费默认 是否显示统一邮费
			ftemt(){
				this.ftem2=true
				this.ftem1=false
			},
			//分类选择
			nactive(num,index=0,chiId=0){
				this['active'+index] = num
				if(index==0){
					let id=this.data.allcategory.parent[num].id
					this.active1=-1
					this.grandchildren=[]
					this.navchind=this.data.allcategory.children[id]
					this.class_id=[]
					this.className=[]
					this.class_id[index]=this.data.allcategory.parent[num].id
					this.className[index]=this.data.allcategory.parent[num].name
					
				}else if(index==1){
					this.grandchildren=this.data.allcategory.children[chiId]
					if(!this.grandchildren){
						this.grandchildren=[]
					}
					this.class_id.splice(2, 1)
					this.className.splice(2, 1)
					this.class_id[index]=this.navchind[num].id
					this.className[index]=this.navchind[num].name
					this.active2=-1
					
				}else{
					this.class_id[index]=this.grandchildren[num].id
					this.className[index]=this.grandchildren[num].name
				}

			},
			//删除分类数据
			del(index){
				 this.classData.splice(index, 1)
			},
			//运费设置
			yfRadio(e){
				this.radioStup=e.target.value
				Object.keys(this.yfsutp).map((item)=>{
					this.yfsutp[item].checked=false
				})
				this.yfsutp[e.target.value].checked=true
			}
		}
	}
</script>

<style>
page{
		background: #fff;
	}
	.fui-header{
		background: #fff;		
	}
	.fui-header uni-navigator,.fui-header .title{
		color: #000;
	}
	.fui-title{
		margin: 30upx 0;
		color: #333;
	}
	.fui-input{
		padding: 0 30rpx;
		position: relative;
	}
	.fui-input input,.fui-input textarea,.fui-choose{
		line-height: 60rpx;
		padding: 0 20rpx;
		background: #f2f2f2;
		border-radius: 10rpx;
	}
	.fui-choose{
		margin: 0 20rpx;
	}
	.fui-input input{
		height: 60rpx;
		margin-bottom: 20rpx;
	}
	.fui-input textarea{
		height: 180rpx;
		width: 100%;
		box-sizing: border-box;
	}
	.fui-navbar{
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.fui-navbar .btn{
		display: block;
		width: 75vw;
		height: 60rpx;
		line-height: 60rpx;
		margin: 0 !important;
		background: #000;
		border-radius: 40rpx;
		color: #fff;
	}
	.container{
		top: 0upx;
	}
	.container .footer .submit,.mini-btn{
		background: #000;
	}

/* 商品分类 */
.small-block {
    padding: 0 10rpx;
    height: auto;
    overflow: hidden;
}
.small-block .item {
    color: #444;
    padding: 5rpx 10rpx;
    background: #e4e4e4;
    border: 1px solid #aaaaaa;
    display: block;
    float: left;
    margin: 0 10rpx 10rpx 0;
}
.small-block .item .icon {
    color: #999;
}
.cate-list {
    height: 410rpx;
    position: relative;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    margin: 10rpx 0;
    padding: 10rpx 0;
	background: #fafafa;
}
.cate-list:before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    border-top: 1px solid #eee;
}
.cate-list:after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    border-bottom: 1px solid #eee;
}
.cate-list .item {
    width: 100%;
    height: 400rpx;
    overflow-y: auto;
    position: relative;
    border-left: 1px solid #eee;
}
.cate-list .item:first-child {
    border: 0;
}
.cate-list .item view {
    height: 60rpx;
    line-height: 60rpx;
    font-size: 28rpx;
    text-align: center;
    color: #666;
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
    padding: 0 .2rem;
}
.cate-list .item view.active {
    background: #eee;
}
.cate-list .item .empty {
    line-height: 400rpx;
    text-align: center;
    font-size: 28rpx;
    color: #999;
	width: 100%;
	display: inline-block;
}
.btn.btn-sm.btn-choose-cate{
	margin: 0 40rpx;
}
.fui-cell-group{
	margin-top: 0;
}
.fui-sku{
	padding: 0 20rpx;
}
.fui-cell-group .fui-cell:before{
	border-top:unset;
}
</style>
